#include <iostream>
#include <vector>
using namespace std;

const int MAX_EQUIPMENGS_QUANTITY = 500;

struct Map
{
	int max_row;
	int max_cloumn;

	int data[MAX_EQUIPMENGS_QUANTITY][MAX_EQUIPMENGS_QUANTITY];

	Map()
	{
		memset( data, 0xff, sizeof(data) );
		max_row = 0;
		max_cloumn = 0;
	}

	void operator &( const Map& diff )
	{
		int cr = max_row, cc = max_cloumn;
		for( int r = cr; r >= 0; r-- )
		{
			for( int c = cc; c >= 0; c-- )
			{
				int t = this->data[r][c];
				if( t == -1 ) continue;

				for( int x = 0; x <= diff.max_row; x++ )
				{
					for( int y = 0; y <= diff.max_cloumn; y++ )
					{
						if( diff.data[x][y] == -1 ) continue;
						if( this->data[r + x][c + y] < t + diff.data[x][y] )
						{
							this->data[r + x][c + y] = t + diff.data[x][y];
							if( this->max_row < r + x ) this->max_row = r + x;
							if( this->max_cloumn < c + y ) this->max_cloumn = c + y;
						}
					}
				}
			}
		}
	}

	void print()
	{
		cout << "row: " << this->max_row + 1 << " cloumn: " << this->max_cloumn + 1 << endl;
		for( int r = 0; r <= max_row; r++ )
		{
			for( int c = 0; c <= max_cloumn; c++ )
			{
				cout << this->data[r][c] << " ";
			}
			cout << endl;
		}
		cout << endl;
	}
};

struct Caravan
{
	int weight;
	int size;
};

int main()
{
	int task = 0;
	while( true )
	{
		int caravans_count = 0;
		cin >> caravans_count;
		if( caravans_count == 0 )
		{
			break;
		}

		int helm_weight = 0, helm_size = 0, helm_defend = 0;
		cin >> helm_weight >> helm_size >> helm_defend;

		int armor_weight = 0, armor_size = 0, armor_defend = 0;
		cin >> armor_weight >> armor_size >> armor_defend;

		int boot_weight = 0, boot_size = 0, boot_defend = 0;
		cin >> boot_weight >> boot_size >> boot_defend;

		int helm_count = 0, armor_count = 0, boot_count = 0, set_defend = 0;
		cin >> helm_count >> armor_count >> boot_count >> set_defend;

		vector<Caravan> caravans( caravans_count );
		for( int i = 0; i < caravans_count; i++ )
		{
			cin >> caravans[i].weight >> caravans[i].size;
		}

		///////////////////////////////////////////////////////////////////////////////
		Map* merge = new Map();
		merge->data[0][0] = 0;

		for( int i = 0; i < caravans_count; i++ )
		{
			Map* diff = new Map();
			int h;
			for( h = 0; helm_weight * h <= caravans[i].weight && helm_size * h <= caravans[i].size ; h++ )
			{
				int left_weight = caravans[i].weight - helm_weight * h;
				int left_size = caravans[i].size - helm_size * h;

				int a;
				for( a = 0; armor_weight * a <= left_weight && armor_size * a <= left_size; a++ )
				{
					int b = min( (left_weight - armor_weight * a) / boot_weight,
								(left_size - armor_size * a) / boot_size );

					diff->data[h][a] = b;
				}
				if( diff->max_cloumn < a - 1 ) diff->max_cloumn = a - 1;
			}
			diff->max_row = h - 1;

			//cout << "diff : caravans " << i + 1 << " diff: " << endl;
			//diff.print();

			*merge & *diff;
			//cout << "merge : caravans " << i + 1 << " diff: " << endl;
			//merge.print();
			delete diff;
		}

		//merge.print();

		int max_defend = 0;
		for( int h = 0; h <= merge->max_row; h++ )
		{
			for( int a = 0; a <= merge->max_cloumn; a++ )
			{
				int b = merge->data[h][a];
				if( b == -1 ) continue;

				int set_count = min( h / helm_count, min( a / armor_count, b / boot_count ) );
				int defend = set_count * set_defend +
					( h - set_count * helm_count ) * helm_defend +
					( a - set_count * armor_count ) * armor_defend +
					( b - set_count * boot_count ) * boot_defend;

				if( max_defend < defend )
				{
					max_defend = defend;
				}
			}
		}

		if( task != 0 )
		{
			cout << endl;
		}
		cout << "Case " << ++task << ": " << max_defend << endl;
		delete merge;
		///////////////////////////////////////////////////////////////////////////////
	}
	return 0;
}
